﻿// Less2DB.NET framework
// http://code.google.com/p/less2db/
//
// Copyright © Wangzhongwu, 2011
// alex.wzw@gmail.com
//

namespace Less2DB.SQLBuilder
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// 查询条件。
    /// </summary>
    public class SQLWhere
    {
        /// <summary>
        /// 查询条件的组合模式。
        /// </summary>
        public enum WhereConnectType
        {
            AND,
            OR
        }

        public SQLWhere(string condition)
        {
            _conditionString = condition;
        }

        /// <summary>
        /// 组合条件对象。
        /// </summary>
        /// <param name="type">组合两条条件的模式。</param>
        /// <param name="condition">条件字符串。</param>
        public SQLWhere Combine(WhereConnectType type, SQLWhere where)
        {
            if (this.ConditionString == null)
                return new SQLWhere(where.ConditionString);
            else
                return new SQLWhere(this.ConditionString + " " + type.ToString() + " " + where.ConditionString);
        }

        private string _conditionString;

        /// <summary>
        /// 获取条件字符串。
        /// </summary>
        public string ConditionString
        {
            get { return _conditionString; }
        }

        /// <summary>
        /// 获取 WHERE 前缀的条件字符串。
        /// </summary>
        public string WhereString
        {
            get { return string.IsNullOrEmpty(this.ConditionString) ? string.Empty : "WHERE " + this.ConditionString; }
        }
    }
}